// view/index/dotaijgdj/dotaijgdj.js
import * as echarts from '../../pages/components/ec-canvass/echarts';
let chart = null
let app = getApp()
let yuming = app.globalData.yuming
var shuzong = []
const request = require('../../config/request');

function initChart(canvas, width, height, dpr) {
  //初始化图表
  chart = echarts.init(canvas, null, {
    width: width,
    height: height,
    devicePixelRatio: dpr
  });
  canvas.setChart(chart);
  var option = {
    legend: {
      // data: ['Allocated Budget', 'Actual Spending']
    },
    radar: {
      // shape: 'circle',
      indicator: [{
          name: '信息采集',
          max: 10000
        },
        {
          name: '监督检查',
          max: 10000
        },
        {
          name: '公众参与',
          max: 10000
        },
        {
          name: '远程监管',
          max: 10000
        },
        {
          name: '企业自律',
          max: 10000
        },
      ],
      radius: 90
    },
    series: [{
      // name: 'Budget vs spending',
      type: 'radar',
      itemStyle: {
        normal: {
          color: "#4565CF", // 图表中各个图区域的边框线拐点颜色
          lineStyle: {
            color: "#4565CF" // 图表中各个图区域的边框线颜色
          },
          areaStyle: {
            type: 'default'
          }
        }
      },
      data: [{
        value: [1000, 5000, 3000, 4000, 8000],
      }, ]
    }]
  };
  /**绘制数据 */
  chart.setOption(option);
  return chart;
}
Page({

  /**
   * 页面的初始数据
   */
  ...request,
  data: {
    yuming: yuming,
    heights: "",
    title: '监管等级',
    ec: {
      lazyLoad: true
    },
    list: [{
        name: '营业执照信息',
        shu: 0,
        content: '营业执照已经完善'
      },
      {
        name: '许可证信息',
        shu: 0,
        content: '许可证已经完善'
      },
      {
        name: '从业人员',
        shu: -1,
        content: '请完善从业人员信息'
      },
      {
        name: '直播监控',
        shu: 0,
        content: '暂未接通视频直播'
      },
      {
        name: '溯源追踪',
        shu: 0,
        content: '根据监管要求定期上报溯源台账'
      },
      {
        name: '投诉处理',
        shu: 0,
        content: '暂未有投诉'
      },
      {
        name: '监管检查',
        shu: 0,
        content: '合格'
      },
      {
        name: '监管抽查',
        shu: 0,
        content: '合格'
      },
      {
        name: '食品安全承诺书',
        shu: 0,
        content: '已签订'
      },
      {
        name: '防疫承诺书',
        shu: 0,
        content: '已签订'
      },
      {
        name: '消杀台账',
        shu: 0,
        content: '已定期完善'
      },
      {
        name: '监管码扫码',
        shu: -2,
        content: '正常'
      }
    ],
    gldj: '',
    cityId: '',
    page: 1,
    start: '开始时间',
    starts: '',
    endtime: '结束时间',
    endtimes: '',
    gofals: false,
    isdian: false,
    khlx_guo: '考核类型',
    khlx_list: [
      // {
      //   name: '系统考核',
      //   sta: '-1'
      // },
      {
        name: '人工考核',
        sta: '1'
      },
      {
        name: '检查考核',
        sta: '2'
      },
    ],
    khlx_sta: '',
    jianguandengjiLIst:[]
  },
  bindkhlx(e) {
    var value = e.detail.value
    console.log(value)
    this.setData({
      khlx_guo: this.data.khlx_list[value].name,
      khlx_sta: this.data.khlx_list[value].sta,
    })
    this.dengji()
  },
  gojians(e) {
    this.setData({
      isdian: true
    })
    console.log(111)
    let url = e.currentTarget.dataset.fil
    var that = this
    var s = url.lastIndexOf(".")
    var b = url.substring(s + 1) //下划线之后
    console.log(b)
    if (b == 'jpg' || b == 'jpeg' || b == 'png') {
      wx.previewImage({
        urls: [url]
      })
    } else {
      wx.showLoading({
        title: '正在打开中',
      })

      wx.downloadFile({
        url: url,
        success(res) {
          var filePath = res.tempFilePath
          console.log(url)
          wx.openDocument({
            filePath: filePath,
            fileType: b,
            success: function (res) {
              wx.hideLoading({
                success: (res) => {},
              })
              that.setData({
                isdian: false
              })
            },
            fail(err) {
              console.log(err)
              wx.hideLoading({
                success: (res) => {},
              })
              wx.showToast({
                title: '打开失败',
                icon: 'none'
              })
              that.setData({
                isdian: false
              })
            }
          })
        },
        fail(err) {
          console.log(err)
          wx.hideLoading({
            success: (res) => {},
          })
          wx.showToast({
            title: '打开失败',
            icon: 'none'
          })
          that.setData({
            isdian: false
          })
        }
      })
    }


  },
  getmore() {
    shuzong = this.data.fxlist
    this.setData({
      page: this.data.page + 1
    })
    this.dengji()
  },
  bindstart(e) {
    shuzong = []
    this.setData({
      start: e.detail.value,
      starts: e.detail.value,
      page: 1,
    })
    this.dengji()
  },
  bindend(e) {
    shuzong = []
    if (new Date(e.detail.value).getTime() <= new Date(this.data.starts).getTime()) {
      wx.showToast({
        title: '结束时间不可<=开始时间',
        icon: 'none'
      })
      this.setData({
        endtime: '结束时间'
      })
    } else {
      this.setData({
        endtime: e.detail.value,
        endtimes: e.detail.value,
        page: 1,
      })
      this.dengji()
    }

  },
  dengji() {
    var url = ''
    if (this.data.cityId == 176) {
      url = 'Jinghexincheng/adminTo_shop_fenxian_log'
    } else {
      url = 'Administrative/adminTo_shop_fenxian_log'
    }
    this.myRequest(yuming + url, {
      shopId: wx.getStorageSync('shopId'),
      page: this.data.page,
      begintime: this.data.starts,
      endtime: this.data.endtimes,
      isOffline: this.data.khlx_sta
    }, "POST").then(res => {
      var data = res.data.data.result
      if (this.data.page == 1) {
        this.setData({
          fxlist: data,
        })
      } else {
        if (data.length < 10) {
          this.setData({
            gofals: true
          })
        }
        this.setData({
          fxlist: shuzong.concat(data),
        })

      }
    })
  },
  gettsList() {
    var that = this;
    wx.showLoading({
      title: '加载中',
      icon: 'none'
    })
    this.myRequest(yuming + 'Shop/shopScoreRanking', {
      shopId: wx.getStorageSync('shopId'),
      page: 1
    }, "POST").then(res => {
      if (res.data.code == 200) {
        wx.hideLoading()
        that.setData({
          shop: res.data.thisShop[0]
        })
      }
    })
  },


  getjianguandengjilistr(){
    var that = this
    this.myRequest('https://msion.86wky.com/zhiyunpatrol.php/' + 'Administrative/shop_gradechange_log',{
      shopId: wx.getStorageSync('shopId'),
      page: 1
    },'POST').then(res => {
      // console.log(res);
      this.setData({
        jianguandengjiLIst:res.data.data.result
      })
    })
  },
  // 数据
  shuju() {
    wx.showLoading({
      title: '加载中',
      icon: 'none'
    })
    this.myRequest(yuming + 'Besall/userAndShopInfo', {
      shopId: wx.getStorageSync('shopId')
    }, "POST").then(res => {
      if (res.data.code == 200) {
        wx.hideLoading();
        this.setData({
          // gldj: res.data.shop.shopGrade,
          gldj: res.data.shopCredit,
          fxfs: res.data.shop.shopScore
        })
      }
    })
  },
  backs() {
    wx.navigateBack({
      delta: 0
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      heights: wx.getMenuButtonBoundingClientRect().top + 5,
      cityId: wx.getStorageSync('jinghe_id')
    })
    this.getjianguandengjilistr()
    this.gettsList()
    this.dengji()
    this.getsmjlList();
    this.oneComponent = this.selectComponent('#mychart-dom-line');
  },
  getPixelRatio() {
    let pixelRatio = 0
    wx.getSystemInfo({
      success: function (res) {
        pixelRatio = res.pixelRatio
      },
      fail: function () {
        pixelRatio = 0
      }
    })
    return pixelRatio
  },
  getsmjlList() {
    wx.showLoading({
      title: '加载中',
      icon: 'none'
    })
    let that = this;
    wx.request({
      url: 'https://msion.86wky.com/Jinghexincheng/five_score_tu',
      data: {
        shopId: wx.getStorageSync('shopId'),
        Year: 2022
      },
      header: {
        'Content-Type': 'application/x-www-form-urlencoded',
        Token: wx.getStorageSync('token'),
      },
      method: 'post',
      success: (res) => {
        wx.hideLoading();
        console.log(res)
        var dpr = this.getPixelRatio()
        this.oneComponent.init((canvas, width, height) => {
          const chart = echarts.init(canvas, null, {
            width: width,
            height: height,
            devicePixelRatio: dpr
          });
          var hydata = res.data.titlelist
          var hyshu = res.data.data
          this.setOptionts(chart, hydata, hyshu);
          return chart;
        });
      },
      fail: (error) => {
        reject(error);
      }
    })
  },
  setOptionts: function (chart, w1, w2) {
    var option = {
      legend: {
        // data: ['Allocated Budget', 'Actual Spending']
      },
      radar: {
        // shape: 'circle',
        indicator: w1,
        radius: 90,

      },
      textStyle: {
        color: '#000',
        fontSize: 13
      },
      series: [{
        // name: 'Budget vs spending',
        type: 'radar',
        itemStyle: {
          normal: {
            color: "#4565CF", // 图表中各个图区域的边框线拐点颜色
            lineStyle: {
              color: "#4565CF" // 图表中各个图区域的边框线颜色
            },
            areaStyle: {
              type: 'default'
            }
          }
        },
        data: [{
          value: w2,
        }]
      }]
    };
    chart.setOption(option);
  },
  setOption: function (chart, option) {
    var option = option;
    chart.setOption(option);
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.shuju()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
})